package com.xingkeduo.tool;

import com.xingkeduo.util.tool.ReturnUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.Instant;

/**
 * @author chi  2019-01-24 17:23
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
public class ResponseReviewUtils<T> {

    /**
     * 存储错误信息
     */
    private String msg = "success";

    private String path;

    private Long timestamp = Instant.now().toEpochMilli();

    private T data;

    private String code;

    private int status;

    private Integer reviews;


    public static <T> ResponseReviewUtils getSuccess(T data,Integer reviews) {
        ResponseReviewUtils<Object> result = ResponseReviewUtils.builder()
                .msg("success")
                .data(data)
                .reviews(reviews)
                .timestamp(Instant.now().toEpochMilli())
                .status(ReturnUtil.Status.SUCCESS.getIndex())
                .build();
        return result;
    }




    /**
     * 错误信息
     *
     * @param msg
     * @param code
     * @return
     */
    public static ResponseReviewUtils error(String msg, String code) {
        ResponseReviewUtils<Object> result = ResponseReviewUtils.builder()
                .msg(msg)
                .timestamp(Instant.now().toEpochMilli())
                .code(code)
                .status(ReturnUtil.Status.FAIL.getIndex())
                .build();
        return result;
    }

    public boolean success(){
        return status == 1;
    }
}

